# -*- coding:utf-8 -*-

from unittest import mock
from common import ReadConfig
from common.HTTPRequests import HTTPRequests


class MyMock:

    @staticmethod
    def mock_requests(request_method, url, expect_data, data, **kwargs):
        """
        :param request_method:
        :param url:
        :param expect_data:
        :param data:
        :param kwargs:
        :return:
        """
        request = HTTPRequests()
        if request_method == 'POST':
            if ReadConfig.MOCK:
                request.post_requests = mock.Mock(return_value=expect_data)
            else:
                request.post_requests = mock.Mock(return_value=expect_data, side_effect=request.post_requests)
            return request.post_requests(url=url, data=data, **kwargs)

        if request_method == 'GET':
            if ReadConfig.MOCK:
                request.get_requests = mock.Mock(return_value=expect_data)
            else:
                request.get_requests = mock.Mock(return_value=expect_data, side_effect=request.get_requests)
            return request.get_requests(url=url, data=data, **kwargs)
